﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Configuration;
using Windvoice.Util;
using Windvoice.User.Model;

namespace Windvoice.User.DataAccess
{
    public class UserDAL
    {
        private string ConnectionString = ConfigurationManager.ConnectionStrings["windvoice"].ToString();

        public int User_Insert(UserInfo user)
        {
            string command = @"INSERT INTO [Users]([username],[email],[user],[sex],[head],[password],[registertime],[lastvisittime],[isonline])
                                VALUES('{0}','{1}','{2}',{3},'{4}','{5}','{6}','{7}',{8})";
            command = String.Format(command, user.UserName, user.Email, user.User, user.Sex, user.Head, user.Password, user.RegisterTime, user.LastvisitTime, user.IsOnline);
            return AccessHelper.ExecuteNonQuery(ConnectionString,command); 
        }

        public int User_ChangeStatus(int UserID, bool IsOnline)
        {
            string command = @"UPDATE [Users] SET [isonline] = "+IsOnline.ToString();
            return AccessHelper.ExecuteNonQuery(ConnectionString, command);
        }

        public DataTable User_GetList()
        {
            string command = "SELECT [id],[username],[email],[user],[sex],[head],[password],[registertime],[lastvisittime],[isonline] FROM [Users]";
            return AccessHelper.ExecuteDataSet(ConnectionString, command).Tables[0];
        }
    }
}
